package com.frog.framework.rekognition.utils;

import software.amazon.awssdk.regions.Region;

import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author wuqiong 2022/11/10
 * @description
 */
public class RekognitionUtils {
    // private static final Set<String> REGION_SET = Region.regions().stream().map(e -> e.id()).collect(Collectors.toSet());
    private static final Integer ARN_LENGTH = 6;
    private static final String ARN_START = "arn:aws";

    /**
     * 检查  arn 合法性
     *
     * @return boolean
     * @author wuqiong 2022/3/4 15:45
     */
    public static boolean checkTopicArn(String topicArn) {
        if (!topicArn.startsWith(ARN_START)) return false;
        String[] split = topicArn.split(":");
        if (split.length < ARN_LENGTH) return false;
        // if (!REGION_SET.contains(split[3])) return false;
        if (split[4] == null || split[4].length() == 0) return false;
        if (!isNumeric(split[4])) return false;
        // 否则为true , 暂时先不检查名称
        return true;
    }


    /**
     * 检查字符是否为数字
     *
     * @return boolean
     * @author wuqiong 2022/3/4 15:42
     */
    private static boolean isNumeric(CharSequence cs) {
        int sz = cs.length();
        for (int i = 0; i < sz; ++i) {
            if (!Character.isDigit(cs.charAt(i))) {
                return false;
            }
        }
        return true;
    }
}
